<?php

/**
 *      [品牌空间] (C)2001-2010 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: imgwater.inc.php 5345 2010-12-02 05:29:46Z yexinhao $
 */

if(!defined('IN_ADMIN')) {
	exit('Acess Denied');
}

$editvalue = array();

$allowvars = array('wwwname', 'wwwurl', 'sitename',
					'seokeywords', 'seodescription', 'mapapikey',
					'sitetel', 'siteqq',
					'allowcache', 'cachemode', 'discounturl', 'attenddescription', 'registerrule', 'miibeian',
					'analytics', 'urltype', 'regurl', 'enablecard', 'commstatus', 'commentmodel', 'enablemap',
					'expiretime',
					'commentperpage', 'noticeperpage', 'goodperpage', 'consumeperpage', 'shopsearchperpage',
					'consumesearchperpage', 'goodsearchperpage',
					'cardperpage', 'albumsearchperpage', 'allowcreateimg', 'fontpath', 'seccode',
					'siteclosed', 'siteclosed_reason', 'multipleshop', 'auditnewshops', 'defaultshopgroup', 'claimshopmsg');//允许提交的settings变量名

//读入缓存
$setting = &$_G['setting'];

if(submitcheck('settingsubmit')) {
	//提交了数据
	$item = $checkresults = array();
	$key = $rpsql = $comma = '';
	$settingnew = &$_G['gp_settingnew'];
	if(!is_array($settingnew) || !$settingnew) {
		array_push($checkresults, array('setting'=>$lang['setting_imgwater_image_watermarkquality_comment']));
	}
	if($checkresults) {
		cpmsg('global_submit_error', '', '', '', true, true, $checkresults);
	}

	$settingnew['watermarkavailable'] = bindec(intval($settingnew['watermarkavailable'][7]).intval($settingnew['watermarkavailable'][6]).intval($settingnew['watermarkavailable'][5]).intval($settingnew['watermarkavailable'][4]).intval($settingnew['watermarkavailable'][3]).intval($settingnew['watermarkavailable'][2]).intval($settingnew['watermarkavailable'][1]));

	$data = array(
		'watermarkavailable' => intval($settingnew['watermarkavailable']),
		'watermarktext' => addslashes(serialize((array)$settingnew['watermarktext'])),
		'watermarkstatus' => intval($settingnew['watermarkstatus']),
		'watermarktype' => (string)$settingnew['watermarktype'],
		'watermarktrans' => intval($settingnew['watermarktrans']),
		'watermarkquality' => intval($settingnew['watermarkquality']),
		'watermarkminheight' => intval($settingnew['watermarkminheight']),
		'watermarkminwidth' => intval($settingnew['watermarkminwidth'])
	);

	foreach($data as $key=>$val) {
		$rpsql[] = "('$key', '$val')";
	}

	if($rpsql) {
		DB::query("REPLACE INTO ".DB::table('settings')." (`variable`, `value`) VALUES ".implode(',', $rpsql));
	}

	updatesettingcache(); //更新设置缓存
	cpmsg('message_success', 'admin.php?action=imgwater');

} else {
	//没有提交数据
	shownav('global', 'menu_imgwater');
	showsubmenu('menu_imgwater');
	showtips('imgwater_tips');
	showformheader('imgwater');

	$watermarkavailable = intval(DB::result_first('SELECT `value` FROM '.DB::table('settings')." WHERE `variable`='watermarkavailable'"));
	$setting['watermarktext'] = (array)unserialize($setting['watermarktext']);
	$setting['watermarkstatus'] = intval($setting['watermarkstatus']);
	$setting['watermarktype'] = (string)$setting['watermarktype'];
	$setting['watermarktrans'] = intval($setting['watermarktrans']);
	$setting['watermarkquality'] = intval($setting['watermarkquality']);
	$setting['watermarkminheight'] = intval($setting['watermarkminheight']);
	$setting['watermarkminwidth'] = intval($setting['watermarkminwidth']);
	$setting['watermarktext']['fontpath'] = str_replace(array('ch/', 'en/'), '', (string)$setting['watermarktext']['fontpath']);

	$fontlist = '<select name="settingnew[watermarktext][fontpath]">';
	$dir = opendir(B_ROOT.'./static/image/fonts/ch');
	while($entry = readdir($dir)) {
		if(in_array(strtolower(fileext($entry)), array('ttf', 'ttc'))) {
			$fontlist .= '<option value="'.$entry.'"'.($entry == $setting['watermarktext']['fontpath'] ? ' selected>' : '>').$entry.'</option>';
		}
	}
	$dir = opendir(B_ROOT.'./static/image/fonts/en');
	while($entry = readdir($dir)) {
		if(in_array(strtolower(fileext($entry)), array('ttf', 'ttc'))) {
			$fontlist .= '<option value="'.$entry.'"'.($entry == $setting['watermarktext']['fontpath'] ? ' selected>' : '>').$entry.'</option>';
		}
	}
	$fontlist .= '</select>';

	$checkwm = array($setting['watermarkstatus'] => 'checked');
	showtableheader('setting_imgwater_image_watermarks');
	showhiddenfields(array('imagelib' => $_G['setting']['imagelib'], 'imageimpath' => $_G['setting']['imageimpath']));
	showsetting('setting_imgwater_available', array('settingnew[watermarkavailable]', array(
		$lang['shop'],
		$lang['notice'],
		$lang['good'],
		$lang['consume'],
		$lang['groupbuy'],
		$lang['album'],
		$lang['album_default'],
	)), $watermarkavailable, 'binmcheckbox');
	showsetting('setting_imgwater_image_watermarkstatus', '', '', '<table style="margin-bottom: 3px; margin-top:3px;"><tr><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="1" '.$checkwm[1].'> #1</td><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="2" '.$checkwm[2].'> #2</td><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="3" '.$checkwm[3].'> #3</td></tr><tr><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="4" '.$checkwm[4].'> #4</td><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="5" '.$checkwm[5].'> #5</td><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="6" '.$checkwm[6].'> #6</td></tr><tr><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="7" '.$checkwm[7].'> #7</td><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="8" '.$checkwm[8].'> #8</td><td><input class="radio" type="radio" name="settingnew[watermarkstatus]" value="9" '.$checkwm[9].'> #9</td></tr></table>');
	showsetting('setting_imgwater_image_watermarkminwidthheight', array('settingnew[watermarkminwidth]', 'settingnew[watermarkminheight]'), array(intval($setting['watermarkminwidth']), intval($setting['watermarkminheight'])), 'multiply');
	showsetting('setting_imgwater_image_watermarktype', array('settingnew[watermarktype]', array(
		array('gif', $lang['setting_imgwater_image_watermarktype_gif'], array('watermarktypeext' => 'none')),
		array('png', $lang['setting_imgwater_image_watermarktype_png'], array('watermarktypeext' => 'none')),
		array('text', $lang['setting_imgwater_image_watermarktype_text'], array('watermarktypeext' => ''))
	)), $setting['watermarktype'], 'mradio');
	showsetting('setting_imgwater_image_watermarktrans', 'settingnew[watermarktrans]', $setting['watermarktrans'], 'text');
	showsetting('setting_imgwater_image_watermarkquality', 'settingnew[watermarkquality]', $setting['watermarkquality'], 'text');
	showtagheader('tbody', 'watermarktypeext', $setting['watermarktype'] == 'text', 'sub');
	showsetting('setting_imgwater_image_watermarktext_text', 'settingnew[watermarktext][text]', $setting['watermarktext']['text'], 'textarea');
	showsetting('setting_imgwater_image_watermarktext_fontpath', '', '', $fontlist);
	showsetting('setting_imgwater_image_watermarktext_size', 'settingnew[watermarktext][size]', $setting['watermarktext']['size'], 'text');
	showsetting('setting_imgwater_image_watermarktext_angle', 'settingnew[watermarktext][angle]', $setting['watermarktext']['angle'], 'text');
	showsetting('setting_imgwater_image_watermarktext_color', 'settingnew[watermarktext][color]', $setting['watermarktext']['color'], 'color');
	showsetting('setting_imgwater_image_watermarktext_shadowx', 'settingnew[watermarktext][shadowx]', $setting['watermarktext']['shadowx'], 'text');
	showsetting('setting_imgwater_image_watermarktext_shadowy', 'settingnew[watermarktext][shadowy]', $setting['watermarktext']['shadowy'], 'text');
	showsetting('setting_imgwater_image_watermarktext_shadowcolor', 'settingnew[watermarktext][shadowcolor]', $setting['watermarktext']['shadowcolor'], 'color');
	showsetting('setting_imgwater_image_watermarktext_imtranslatex', 'settingnew[watermarktext][translatex]', $setting['watermarktext']['translatex'], 'text');
	showsetting('setting_imgwater_image_watermarktext_imtranslatey', 'settingnew[watermarktext][translatey]', $setting['watermarktext']['translatey'], 'text');
	showsetting('setting_imgwater_image_watermarktext_imskewx', 'settingnew[watermarktext][skewx]', $setting['watermarktext']['skewx'], 'text');
	showsetting('setting_imgwater_image_watermarktext_imskewy', 'settingnew[watermarktext][skewy]', $setting['watermarktext']['skewy'], 'text');
	showtagfooter('tbody');
	//showsetting('setting_imgwater_preview', '', '', cplang('setting_imgwater_preview_button'));
	showsubmit('settingsubmit', 'submit');
	showtablefooter();
	showformfooter();
	bind_ajax_form();
}

?>